﻿using Itech_Run.HttpApi.Shared.Result;
using Itech_Run.Helper.Attribute;
using Itech_Run.HttpApi.Shared;
using Itech_Run.Sys.Application.Contracts.Dto;
using Itech_Run.Sys.Application.Contracts.Service;
using Microsoft.AspNetCore.Mvc;

namespace Itech_Run.Sys.HttpApi.Controllers
{
    public class SysDictionaryController : BaseApiController
    {
        private readonly ISysDictionaryService _sysDictionaryService;
        public SysDictionaryController(ISysDictionaryService sysDictionaryService)
        {
            _sysDictionaryService = sysDictionaryService;
        }

        [HttpGet]
        public async Task<CustomResult> GetCodeTypeListAsync()
        {
            return new CustomResult(await _sysDictionaryService.GetCodeTypeListAsync());
        }

        [HttpGet]
        public async Task<CustomResult> GetItemByCodeTypeAsync(string codeType)
        {
            return new CustomResult(await _sysDictionaryService.GetItemByCodeTypeAsync(codeType));
        }

        [HttpGet]
        public async Task<CustomResult> GetAsync(string id)
        {
            return new CustomResult(await _sysDictionaryService.GetAsync(id));
        }

        [HttpPost]
        public async Task<CustomResult> GetListAsync(SysDictionaryListDto listDto)
        {
            return new CustomResult(await _sysDictionaryService.GetListAsync(listDto));
        }

        [ButtonAuth(ButtonAuthConst.add)]
        [HttpPost]
        public async Task<CustomResult> InsertAsync(SysDictionaryCreateDto dto)
        {
            string operateUser = GetOperateId();
            return new CustomResult(await _sysDictionaryService.InsertAsync(dto, operateUser));
        }

        [ButtonAuth(ButtonAuthConst.edit)]
        [HttpPost]
        public async Task<CustomResult> UpdateAsync(SysDictionaryUpdateDto dto)
        {
            string operateUser = GetOperateId();
            return new CustomResult(await _sysDictionaryService.UpdateAsync(dto, operateUser));
        }

        [ButtonAuth(ButtonAuthConst.delete)]
        [HttpPost]
        public async Task<CustomResult> DeleteAsync(string id)
        {
            await _sysDictionaryService.DeleteAsync(id);
            return GetSuccesResult();
        }
    }
}
